import { Injectable } from '@nestjs/common';
import PersonEntity from '@app/db/model/entity/person.entity';
import { UserInfoDTO } from '@app/db/model/dto/user.dto';
import { InjectModel } from '@nestjs/mongoose';
import { UserEntityModel, UserSchema } from 'libs/mdb/model/user.entity';
import { model, Schema } from 'mongoose';

@Injectable()
export class UserService {
  async getUserInfo(): Promise<UserInfoDTO> {
    let result = await PersonEntity.findOne({ id: 1 });
    let res = new UserInfoDTO();

    res.code = result.id;
    res.name = result.name;

    return res;
  }

  getPersonInfo() {
    // let person = new UserEntityModel();
    // person.firstName = 'zhanshan';
    // person.lastName = 'zhang';
    // person.schema = UserSchema;

    // return await person.save();

    const Cat = model(
      'Cat',
      new Schema({
        name: String,
        age: Number,
        breed: String,
      }),
    );

    const kitty = new Cat({ name: 'Zildjian', age: 12, breed: 'yellow' });
    return kitty.save();
  }
}
